package com.zxy.supplier_system.server.entity

import jakarta.persistence.*
import org.hibernate.annotations.DynamicInsert
import org.hibernate.annotations.DynamicUpdate
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.OffsetDateTime

/**
 * 子商品具有不同的名称和唯一性编号，分别管理库存
 */
@EntityListeners(AuditingEntityListener::class)
@Table(
    uniqueConstraints = [
        UniqueConstraint(
            name = "subgoods_goods_id_number_uindex",
            columnNames = ["number", "goods_id"]
        )
    ]
)
@DynamicUpdate
@DynamicInsert
@Entity
class SubGoods {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id:Int?=null
    lateinit var number:String

    lateinit var name:String

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(nullable = false)
    lateinit var goods: Goods

    @CreatedDate
    lateinit var createdDateTime: OffsetDateTime

    @LastModifiedDate
    var lastModifiedDateTime: OffsetDateTime? = null

    var amount: Int = 0

}
